/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DatabaseConnection;

import Entities.StopPoint;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author serhat
 */
public class StopPointDbConnection extends Connector {

    public StopPointDbConnection() throws ClassNotFoundException,
            SQLException, InstantiationException, IllegalAccessException {
    }

    private String buildInsertQuery(StopPoint stopPoint) {
        String query = String.format(
                "INSERT INTO Durak "
                + "VALUES(NULL, '%d', '%s', '%s', '%s')",
                stopPoint.getRouteId(),
                stopPoint.getName(),
                stopPoint.getDate(),
                stopPoint.getTime());
        System.out.println(query);
        return query;
    }

    public boolean insert(StopPoint stopPoint) {
        try {
            String query = buildInsertQuery(stopPoint);
            executeUpdate(query);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(StopPointDbConnection.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }

    private String buildSelectQuery(StopPoint stopPoint) {
        String query = String.format(
                "Select durakNo from Durak where sefer = '%d'"
                + "and ad = '%s'", stopPoint.getRouteId(), stopPoint.getName());
        return query;
    }
    
    public ResultSet select(StopPoint stopPoint){
        try {
            String query = buildSelectQuery(stopPoint);
            ResultSet rs = executeQuery(query);
            return rs;
        } catch (SQLException ex) {
            Logger.getLogger(StopPointDbConnection.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
        
    }
}
